<?php 
	class Db_gift extends CI_Model{
		public function __construct(){
			parent::__construct();
		}
		
		public function gift_list(){			
			if($this->session->userdata("sess_customer_name") != "eshine"){
				$this->db->where("customer_pkid",$this->session->userdata("sess_customer_id"));
			}
			$res = $this->db->get("mobile_gift");
			//==
			$i = 1;
			$arr = $res->result_array();
			$item = array();
			foreach ($arr as $P){
				$tmp['pkid']						=$P['pkid'];
				$tmp['name']						=$P['name'];
				$this->db->where("pkid",$P['customer_pkid']);
				$rows = $this->db->get("mobile_customer")->row();
				$tmp['c_name']					=$rows->name;
				$tmp['content']					=$P['content'];
				$tmp['status']						=$P['status'];
				$item[] = $tmp;
			}
			return array($item);
		}
		
		public function gift_code_list(){
			 $this->db->select("t1.pkid,t2.name as g_name,t1.created_date,t3.name as m_name,t1.code");
			 $this->db->from("mobile_code_gift t1");
			 $this->db->join("mobile_gift t2","t1.gift_pkid=t2.pkid","left");
			 $this->db->join("mobile_member_gift t3","t1.member_pkid=t3.pkid");
			 if($this->session->userdata("sess_customer_name") != "eshine"){
			 	$this->db->where("t3.customer_pkid",$this->session->userdata("sess_customer_id"));
			 }
			 $this->db->order_by("t1.pkid",'desc');
			 $res = $this->db->get();
			//==
			$arr = $res->result_array();
			$item = array();
			foreach ($arr as $P){
				$tmp['pkid']							=$P['pkid'];
				$tmp['g_name']						=$P['g_name'];
				$tmp['m_name']						=$P['m_name'];
				$tmp['code']							=$P['code'];
				$tmp['created_date']				=$P['created_date'];
				$item[] = $tmp;
			}
			return array($item);
		}
		
		
		public function member_list(){
			if($this->session->userdata("sess_customer_name") != "eshine"){
				$this->db->where("customer_pkid",$this->session->userdata("sess_customer_id"));
			}
			$this->db->order_by("pkid",'desc');
			$res = $this->db->get("mobile_member_gift");
			//==
			$arr = $res->result_array();
			$item = array();
			foreach ($arr as $P){
				$tmp['pkid']							=$P['pkid'];
				$tmp['name']							=$P['name'];
				$tmp['tel']								=$P['tel'];
				$tmp['email']							=$P['email'];
				$tmp['id_pc']								=$P['id_pc'];
				$tmp['imei']							=$P['imei'];
				$tmp['point']							=$P['point'];
				$item[] = $tmp;
			}
			return array($item);
		}
	}
?>